package com.piggy.sys.controller;

import com.piggy.common.core.constant.SecurityConstants;
import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.FeignResultUtils;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.api.RemoteLogiPricePlanService;
import com.piggy.logi.sys.api.bo.LogiPricePlanExtEditBo;
import com.piggy.logi.sys.api.bo.LogiPricePlanQueryBo;
import com.piggy.logi.sys.api.vo.LogiPricePlanExtVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 价格方案管理Controller
 *
 * @author piggy
 * @date 2023-08-14
 */
@Api(value = "价格方案管理控制器", tags = {"价格方案管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/logi/plan")
public class LogiPricePlanController extends BaseController {

    @Resource
    private RemoteLogiPricePlanService iLogiPricePlanService;

    /**
     * 查询价格方案管理列表
     */
    @ApiOperation("查询价格方案管理列表")
    //@SaCheckPermission("sys:plan:list")
    @PostMapping("/list")
    public TableDataInfo<LogiPricePlanExtVo> list(@Validated @RequestBody LogiPricePlanQueryBo bo) {
        TableDataInfo<LogiPricePlanExtVo> page = iLogiPricePlanService.innerList(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(page);
        return page;
    }

    /**
     * 查询价格方案管理列表
     */
    @ApiOperation("查询价格方案管理列表")
    //@SaCheckPermission("sys:plan:list")
    @PostMapping("/queryList")
    public List<LogiPricePlanExtVo> queryList(@Validated @RequestBody LogiPricePlanQueryBo bo) {
        R<List<LogiPricePlanExtVo>> list = iLogiPricePlanService.queryInnerList(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(list);
        return list.getData();
    }

    /**
     * 获取价格方案管理详细信息
     */
    @ApiOperation("获取价格方案管理详细信息")
    //@SaCheckPermission("sys:plan:query")
    @GetMapping("/{id}")
    public R<LogiPricePlanExtVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable("id") Long id) {
        R<LogiPricePlanExtVo> r = iLogiPricePlanService.innerInfo(id, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

    /**
     * 新增价格方案管理
     */
    @ApiOperation("新增价格方案管理")
    //@SaCheckPermission("sys:plan:add")
    @LogiLog(title = "价格方案管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiPricePlanExtVo> add(@Validated @RequestBody LogiPricePlanExtEditBo bo) {
        //bo.setDeptId(SecurityUtils.getMainDeptId());
        R<LogiPricePlanExtVo> r = iLogiPricePlanService.innerAdd(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

    /**
     * 修改价格方案管理
     */
    @ApiOperation("修改价格方案管理")
    //@SaCheckPermission("sys:plan:edit")
    @LogiLog(title = "价格方案管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiPricePlanExtVo> edit(@Validated @RequestBody LogiPricePlanExtEditBo bo) {
        //bo.setDeptId(SecurityUtils.getMainDeptId());
        R<LogiPricePlanExtVo> r = iLogiPricePlanService.innerEdit(bo, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

    /**
     * 删除价格方案管理
     */
    @ApiOperation("删除价格方案管理")
    //@SaCheckPermission("sys:plan:remove")
    @LogiLog(title = "价格方案管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        R<Integer> r = iLogiPricePlanService.innerRemove(ids, SecurityConstants.INNER);
        FeignResultUtils.throwIfFailed(r);
        return r;
    }

}
